package TCP;

import java.io.*;
import java.net.*;

public class TestClient {
	public Socket socket;
	public PrintWriter out;
	public BufferedReader in;

	public TestClient() {
		socket = null;
		out = null;
		in = null;
	}

	public void connect() {
		try {
			socket = new Socket("localhost", 9999);
			out = new PrintWriter(socket.getOutputStream(), true);
			in = new BufferedReader(new InputStreamReader(
					socket.getInputStream()));
		} catch (UnknownHostException e) {
			System.err.println("Client: Unknown host.");
			System.exit(1);
		} catch (IOException e) {
			System.err.println("Client: IO error.");
			System.exit(1);
		}
	}
	
	public void send(String cmd) {
		try {
			out.println(cmd);
			System.out.println("client received: "+in.readLine());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
